

using System.Drawing;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using Styx;
    using Styx.CommonBot.Database;
    using Styx.Helpers;
    using Styx.Loaders;
    using Styx.CommonBot.AreaManagement;
    using Styx.CommonBot.AreaManagement.Triangulation;
    using Styx.TreeSharp;
    using Styx.CommonBot.Inventory;
    using Styx.CommonBot.Frames;
    using Styx.Pathing;
    using Styx.Pathing.OnDemandDownloading;
    using Styx.Patchables;
    using Styx.Plugins;
    using Styx.WoWInternals;
    using Styx.WoWInternals.Misc;
    using Styx.WoWInternals.Misc.DBC;
    using Styx.WoWInternals.World;
    using Styx.WoWInternals.WoWCache;
    using Styx.WoWInternals.WoWObjects;
    using System.Diagnostics;

namespace AzeniusHelper
{
    public class AzeniusHelper : HBPlugin
    {

        #region Boring Plugin Info

        public override string Name { get { return "Pandaria Dailies"; } }
        public override string Author { get { return "Megser (Modified by Vego)"; } }
        public override Version Version { get { return new Version(1,0,1); } }
        public override bool WantButton { get { return true; } }
        public override string ButtonText { get { return "No Config"; } }

        #endregion
		
		private static readonly LocalPlayer Me = StyxWoW.Me;
		private static Stopwatch GlobalTimer = new Stopwatch();
		
        #region List of WoWUnits and WoWGameObjects needed
		
		public List<WoWUnit> PandarenSpirit
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 59231 && u.Distance < 5).OrderBy(u => u.Distance).ToList();
            }
        }
		
		public List<WoWUnit> ShaoTienMindbinder
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63221 && u.Distance < 5).OrderBy(u => u.Distance).ToList();
            }
        }
		
		public List<WoWUnit> BrazierFire
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63787 && u.Distance < 5).OrderBy(u => u.Distance).ToList();
            }
        }

		public List<WoWUnit> Tormentor
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 59238 && u.Distance < 15 && !u.IsDead).OrderBy(u => u.Distance).ToList();
            }
        }


		public List<WoWUnit> Behemoth
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 65824 && u.Distance < 30).OrderBy(u => u.Distance).ToList();
            }
        }

		public List<WoWUnit> Krichon
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63978 && u.Distance < 30).OrderBy(u => u.Distance).ToList();
            }
        }


		public List<WoWUnit> Cracklefang
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 58768 && u.Distance < 30).OrderBy(u => u.Distance).ToList();
            }
        }


		public List<WoWUnit> Sydow
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63240 && u.Distance < 30).OrderBy(u => u.Distance).ToList();
            }
        }


		public List<WoWUnit> MantidNiuzao
        {
            get
            {
                return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 61502 || u.Entry == 61508 || u.Entry == 61509 && u.Distance < 50 && !u.IsDead).OrderBy(u => 

u.Distance).ToList();
            }
        }
		
		//public List<WoWUnit> DreadKunchong
       // {
         //   get
         //   {
          //      return ObjectManager.GetObjectsOfType<WoWUnit>()
            //                        .Where(u => u.Entry == 64717 && !u.IsDead)
             //                       .OrderBy(u => u.Distance).ToList();
          //  }
      //  }
		
        #endregion
		
		#region Some Quest Helper Functions
        
        public bool IsOnQuest(uint questId)
        {
            return Me.QuestLog.GetQuestById(questId) != null && !Me.QuestLog.GetQuestById(questId).IsCompleted;
        }

        public bool QuestComplete(uint questId)
        {
            return Me.QuestLog.GetQuestById(questId).IsCompleted;
        }
        

        public bool QuestFailed(uint questId)
        {
            return Me.QuestLog.GetQuestById(questId).IsFailed;
        }

        public bool ItemOnCooldown(uint ItemId)
        {
            return Lua.GetReturnVal<bool>("GetItemCooldown(" + ItemId + ")", 0);

        }

        public void UseQuestItem(uint ItemId)
        {
            Lua.DoString("UseItemByName(" + ItemId + ")");
        }

        public void UseIfNotOnCooldown(uint ItemId)
        {
            if (!ItemOnCooldown(ItemId))
            {
                UseQuestItem(ItemId);
            }
        }

        public bool QuestObjectiveComplete(uint questId, int objectiveNum) {
            return (Lua.GetReturnVal<int>("a,b,c=GetQuestLogLeaderBoard(" + objectiveNum + ",GetQuestLogIndexByID(" + questId + "));if c==1 then return 1 else return 0 end", 0) == 1);
        }

        public bool TargetingNpc(uint npcId) {
            return Me.CurrentTarget.Entry == npcId;
        }

        public bool HasQuest(uint questId) {
            return Me.QuestLog.GetQuestById(questId) != null;
        }
		
        #endregion

        public override void Pulse()
        {
			
			if (IsOnQuest(30231))
            {
                UseIfNotOnCooldown(79344); // Pomharvest Firework
            }
			
			if (IsOnQuest(30320) && (PandarenSpirit.Count >= 1))
            {
                   PandarenSpirit[0].Target();
                   PandarenSpirit[0].Interact();
            }
			
			if (IsOnQuest(30192) && (BrazierFire.Count >= 1))
            {
                   BrazierFire[0].Interact();
            }

			
               if (Me.HasAura("Lightning Pool"))
                {
                    Lua.DoString("StrafeLeftStart()"); // Strafe Left if we're in a pool
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }

			if (IsOnQuest(30320))
            {
		
               if (Me.HasAura("Spirit Void") && Tormentor[0].Location.Distance(Me.Location) < 10)
                {
                    Lua.DoString("JumpOrAscendStart()"); // Fly when Tormentor targeting me
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }
            }

			if (IsOnQuest(31762))
            {

               if (Behemoth[0].IsCasting && !Me.IsBehind(Behemoth[0]))
                {
                    Lua.DoString("StrafeLeftStart()");
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }

	    }


			if (IsOnQuest(30482))
            {

               if ((Sydow[0].CastingSpellId == 126347))
                {
                    Lua.DoString("StrafeLeftStart()");
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }

	    }

			if (IsOnQuest(30249))
            {

               if (Krichon[0].IsCasting && !Me.IsBehind(Krichon[0]))
                {
                    Lua.DoString("StrafeLeftStart()");
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }

	    }


			if (IsOnQuest(30233))
            {

               if (Cracklefang[0].IsCasting && !Me.IsBehind(Cracklefang[0]))
                {
                    Lua.DoString("StrafeLeftStart()");
                    Thread.Sleep(1000);
                    WoWMovement.MoveStop();
                }

	    }


			if (IsOnQuest(30952) || IsOnQuest(30953) || IsOnQuest(30954) || IsOnQuest(30955) || IsOnQuest(30956) || IsOnQuest(30957) || IsOnQuest(30958) || IsOnQuest(30959))
            {

               if (Me.Combat && Me.IsMoving)
                {
		    ObjectManager.Update();
                    Thread.Sleep(200);
		    MantidNiuzao[0].Target();
                    Thread.Sleep(1000);
                }

	    }
		
			
			#region Quest 30293 - In Enemy Hands

            if (IsOnQuest(30293) && (ShaoTienMindbinder.Count >= 1))
            {
				ShaoTienMindbinder[0].Target();
            }
            #endregion


        }
    }
}









